package com.lizhiyu.flink.demo3_sink.redis;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * Apache中的的bahir 通过sink 向redis中存信息，对应的redis的扩展的实现
 * 单节点redis存储hset类型数据，通过tuple进行分组和聚合
 */
public class RedisExampleMapper implements RedisMapper<Tuple2<String, Integer>> {

    @Override
    public RedisCommandDescription getCommandDescription() {
        //存储的数据结构是什么，名字是什么
        return new RedisCommandDescription(RedisCommand.SET, "STRING_NAME");

        //存储的数据结构是什么，名字是什么
//        return new RedisCommandDescription(RedisCommand.HSET, "HASH_NAME");
    }

    @Override
    public String getKeyFromData(Tuple2<String, Integer> data) {
        //key 是什么
        return data.f0;
    }

    @Override
    public String getValueFromData(Tuple2<String, Integer> data) {
        //value是什么
        return String.valueOf(data.f1);
    }
}
